<?php
	class TradeModel extends Model{
		public $BusinessProblemId;	//商业问题ID（_get('id')）
		public $teamofficer;		//该问题所属的企业的教官的信息
		//public $Probleminfo;		//竞赛项目的详细信息
		
		public function __construct($BusinessProblemId){
			$this->BusinessProblemId=$BusinessProblemId;
			if(!$this->checkid()){
				$this->BusinessProblemId = false;
				return false;
			}
			$this->teamofficer = $this->getteamofficer();
		}
		
		//商业问题ID检测
		public function checkid(){
			if(!$this->BusinessProblemId){
				return false;
			}else{
				if($res = M()->query('select Id from businessproblems where Id = '.$this->BusinessProblemId))
					return $res[0]['Id'];
				else
					return false;
			}
		}
		
		//查询该问题所属的企业的教官的信息
		public function getteamofficer(){
			return $info = M()->query('
				SELECT u.UserId,u.TrueName ,u.Avatar
				FROM businessproblems b,enterprise e,teacher t,users u 
				WHERE b.Id='.$this->BusinessProblemId.'
				and b.EnterpriseId=e.Id 
				and e.Id=t.EnterpriseId 
				and t.UserId=u.UserId 
			');
		}
		
		//竞赛项目的详细信息
		public function getProbleminfo(){
			$info = M()->query(' 
				select b.Id,b.Title,e.Id as eid,e.Name,e.Introduce,b.Goal,b.Description,b.Support,b.Advise 
				from businessproblems b,enterprise e 
				where b.Id='.$this->BusinessProblemId.' 
				and b.EnterpriseId = e.Id 
			');
			return $info[0];
		}
		
		//选择该竞赛项目的团队
		public function getselectedteam(){
			$info = M()->query(' 
				select t.Id,t.Name,t.Logo
				from project p,team t
				where p.ProblemId = '.$this->BusinessProblemId.' 
				and p.TeamId=t.Id
			');
			return $info;
		}
	}
?>